import datetime
from dateutil.relativedelta import relativedelta

# 减去一天
# (datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
# # 减去一年
# (datetime.datetime.now() - relativedelta(years=1)).strftime("%Y-%m-%d")
# # 减去一月
# (datetime.datetime.now() - relativedelta(months=1)).strftime("%Y-%m-%d")
# # 减去一周
# (datetime.datetime.now() - relativedelta(weeks=1)).strftime("%Y-%m-%d")
# # 明天
# (datetime.datetime.now() + datetime.timedelta(days=1)).strftime("%Y-%m-%d")


def get_datetime_by_week(week_num=0):
    return datetime.datetime.now() - datetime.timedelta(weeks=week_num)


def get_datetime(day_num=0):
    return datetime.datetime.now() - datetime.timedelta(days=day_num)


def get_datetime_by_num_format(day_num, format_str="%Y%m%d"):
    dt = get_datetime(day_num)
    return dt.strftime(format_str)


